package com.lzx.indicatordemo.demo;

import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.viewpager.widget.ViewPager;

import com.framework.view.indicator.GodIndicator;
import com.framework.view.indicator.GodIndicatorAdapter;
import com.framework.view.indicator.configs.GlobalConfig;
import com.framework.view.indicator.configs.MidDividerConfig;
import com.framework.view.indicator.configs.TextTitleConfig;
import com.framework.view.indicator.indicators.configs.LineIndicatorConfig;
import com.framework.view.indicator.model.IndicatorShapeType;
import com.framework.view.indicator.model.IndicatorWidthModel;
import com.lzx.indicatordemo.Constants;
import com.lzx.indicatordemo.ExamplePagerAdapter;
import com.lzx.indicatordemo.R;

import java.util.Arrays;
import java.util.List;

import static com.lzx.indicatordemo.Constants.CHANNELS;
import static com.lzx.indicatordemo.Constants.CHANNELS3;
import static com.lzx.indicatordemo.Constants.normalTxtColor;
import static com.lzx.indicatordemo.Constants.normalTxtColors;
import static com.lzx.indicatordemo.Constants.selectedTxtColor;
import static com.lzx.indicatordemo.Constants.selectedTxtColors;

/**
 * description
 *
 * @author liangzx
 * @version 1.0
 * @time 2019-12-23 10:53
 **/
public class LineIndicatorDemoActivity extends AppCompatActivity {

    private List<String> mDataList = Arrays.asList(CHANNELS);
    private ViewPager mViewPager;
    private ExamplePagerAdapter mExamplePagerAdapter = new ExamplePagerAdapter(mDataList);

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.line_indicator_demo_activity);

        mViewPager = findViewById(R.id.vp);
        mViewPager.setAdapter(mExamplePagerAdapter);
        init1();
        init2();
        init3();
        init4();
        init5();
        init6();
        init7();
        init8();
    }

    private void init1() {
        GodIndicator godIndicator = findViewById(R.id.g1);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        final GodIndicatorAdapter<LineIndicatorConfig> adapter = new GodIndicatorAdapter<LineIndicatorConfig>() {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                return TextTitleConfig.factory()
                        .setNormalColors(normalTxtColors)
                        .setSelectedColors(selectedTxtColors)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40)
                        .setMidDividerConfig(MidDividerConfig.factory()
                                .setColor(Color.WHITE)
                                .setWidth(5)
                                .setHeight(30));
            }

            @Override
            protected LineIndicatorConfig bindIndicatorConfig() {
                return LineIndicatorConfig.factory()
                        .setTop()
                        .setWidthModel(IndicatorWidthModel.MATCH_EDGE)
                        .setColors(Constants.indicatorColors)
                        .setShapeType(IndicatorShapeType.ROUND_RECT)
                        .setPendingLeft(10)
                        .setPendingTop(5)
                        .setRoundRadius(10)
                        .setPendingRight(10);
            }
        };
        godIndicator.setAdapter(adapter);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                adapter.bindViewPager(mViewPager);
            }
        }, 3000);
    }

    private void init2() {
        GodIndicator godIndicator = findViewById(R.id.g2);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        final GodIndicatorAdapter adapter = new GodIndicatorAdapter<LineIndicatorConfig>() {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                return TextTitleConfig.factory()
                        .setNormalColor(normalTxtColor)
                        .setSelectedColor(selectedTxtColor)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40)
                        .setSelectedBold(true)
                        .setMidDividerConfig(MidDividerConfig.factory()
                                .setColor(Color.WHITE)
                                .setWidth(5)
                                .setHeight(LinearLayout.LayoutParams.MATCH_PARENT)
                                .setMarginBottom(20)
                                .setMarginTop(20));
            }

            @Override
            public String getTitleName(int position) {
                return CHANNELS[position+3];
            }

            @Override
            public int getCount() {
                return 3;
            }

            @Override
            protected void bindGlobalConfig(GlobalConfig config) {
                config.setPercentAfterScroll(0.3f)
                        .setCanOffScreen(false);
            }

            @Override
            protected LineIndicatorConfig bindIndicatorConfig() {
                return null;
            }
        };
        adapter.bindViewPager(mViewPager);
        godIndicator.setAdapter(adapter);
    }

    private void init3() {
        GodIndicator godIndicator = findViewById(R.id.g3);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<LineIndicatorConfig>(mViewPager) {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                return TextTitleConfig.factory()
                        .setNormalColor(normalTxtColor)
                        .setSelectedColor(selectedTxtColor)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40)
                        .setSelectedBold(true)
                        .setMidDividerConfig(MidDividerConfig.factory()
                                .setColor(Color.WHITE)
                                .setWidth(5)
                                .setHeight(LinearLayout.LayoutParams.MATCH_PARENT)
                                .setMarginLeft(20)
                                .setMarginRight(20)
                                .setMarginBottom(20)
                                .setMarginTop(20));
            }

            @Override
            public String getTitleName(int position) {
                return CHANNELS3[position];
            }

            @Override
            public int getCount() {
                return CHANNELS3.length;
            }

            @Override
            protected LineIndicatorConfig bindIndicatorConfig() {
                return LineIndicatorConfig.factory()
                        .setRoundRadius(10)
//                        .setColorFollowSlideChange(true)
                        .setWidthModel(IndicatorWidthModel.SELF_DEFINE)
                        .setWidth(100)
                        .setColors(Constants.indicatorColors);
            }
        });
    }

    private void init4() {
        GodIndicator godIndicator = findViewById(R.id.g4);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<LineIndicatorConfig>(mViewPager) {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                TextTitleConfig config = TextTitleConfig.factory()
                        .setNormalColor(normalTxtColor)
                        .setSelectedColor(selectedTxtColor)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40)
                        .setSelectedBold(true)
                        .setNormalBold(true)
                        .setMidDividerConfig(MidDividerConfig.factory()
                                .setColor(Color.WHITE)
                                .setWidth(20)
                                .setHeight(LinearLayout.LayoutParams.MATCH_PARENT)
                                .setRoundRadius(10)
                                .setMarginLeft(20)
                                .setMarginRight(20)
                                .setMarginBottom(20)
                                .setMarginTop(20));
                return config;
            }

            @Override
            protected LineIndicatorConfig bindIndicatorConfig() {
                return LineIndicatorConfig.factory()
                        .setRoundRadius(10)
                        .setWidthModel(IndicatorWidthModel.WARP_CONTENT)
                        .setColor(Constants.randomIndicatorColor());
            }

        });
    }

    private void init5() {
        final GodIndicator godIndicator = findViewById(R.id.g5);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<LineIndicatorConfig>(mViewPager) {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                Drawable drawable = ContextCompat.getDrawable(LineIndicatorDemoActivity.this, R.drawable.vertical_dash_line);

                TextTitleConfig config = TextTitleConfig.factory()
                        .setNormalColor(normalTxtColor)
                        .setSelectedColor(selectedTxtColor)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40).setMidDividerConfig(MidDividerConfig.factory()
                                .setDrawable(drawable)
                                .setWidth(20)
                                .setHeight(LinearLayout.LayoutParams.MATCH_PARENT)
                                .setMarginLeft(20)
                                .setMarginRight(20)
                                .setMarginBottom(20)
                                .setMarginTop(20));
                return config;
            }

            @Override
            public String getTitleName(int position) {
                return CHANNELS[position];
            }

            @Override
            public int getCount() {
                return CHANNELS.length;
            }

            @Override
            protected LineIndicatorConfig bindIndicatorConfig() {
                return LineIndicatorConfig.factory()
                        .setShapeType(IndicatorShapeType.CIRCLE)
                        .setHeight(20)
                        .setPendingBottom(10)
                        .setColors(Constants.indicatorColors)
                        .setWidthModel(IndicatorWidthModel.SELF_DEFINE);
            }

        });
    }

    private void init6() {
        GodIndicator godIndicator = findViewById(R.id.g6);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<LineIndicatorConfig>(mViewPager) {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                TextTitleConfig config = TextTitleConfig.factory()
                        .setNormalColor(normalTxtColor)
                        .setSelectedColor(selectedTxtColor)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40);
                return config;
            }

            @Override
            public String getTitleName(int position) {
                return CHANNELS[position];
            }

            @Override
            public int getCount() {
                return CHANNELS.length;
            }

            @Override
            protected LineIndicatorConfig bindIndicatorConfig() {
                return LineIndicatorConfig.factory()
                        .setHeight(10)
                        .setColors(Constants.indicatorColors)
                        .setShowSharpCorner(true)
                        .setSharpCornerHeight(10)
                        .setSharpCornerWidth(20);
            }

        });
    }

    private void init7() {
        GodIndicator godIndicator = findViewById(R.id.g7);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<LineIndicatorConfig>(mViewPager) {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                TextTitleConfig config = TextTitleConfig.factory()
                        .setNormalColor(normalTxtColor)
                        .setSelectedColor(selectedTxtColor)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40);
                return config;
            }

            @Override
            public String getTitleName(int position) {
                return CHANNELS[position];
            }

            @Override
            public int getCount() {
                return CHANNELS.length;
            }

            @Override
            protected LineIndicatorConfig bindIndicatorConfig() {
                return LineIndicatorConfig.factory()
                        .setTop()
                        .setShapeType(IndicatorShapeType.ROUND_RECT)
                        .setRoundRadius(10)
                        .setHeight(10)
                        .setColors(Constants.indicatorColors)
                        .setShowSharpCorner(true)
                        .setSharpCornerHeight(10)
                        .setSharpCornerWidth(20);
            }

        });
    }

    private void init8() {
        GodIndicator godIndicator = findViewById(R.id.g8);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<LineIndicatorConfig>(mViewPager) {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                TextTitleConfig config = TextTitleConfig.factory()
                        .setNormalColor(normalTxtColor)
                        .setSelectedColor(selectedTxtColor)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40);
                return config;
            }

            @Override
            public String getTitleName(int position) {
                return CHANNELS[position];
            }

            @Override
            public int getCount() {
                return CHANNELS.length;
            }

            @Override
            protected LineIndicatorConfig bindIndicatorConfig() {
                return LineIndicatorConfig.factory()
                        .setShapeType(IndicatorShapeType.CIRCLE)
                        .setRadius(20)
                        .setUseBezierEffect(true)
                        .setWidthModel(IndicatorWidthModel.WARP_CONTENT)
                        .setColor(Constants.randomIndicatorColor());
            }

        });
    }
}
